<?php

namespace App\Admin\Metrics\Examples;

use App\Models\BlockedUser;
use App\Models\Setting;
use App\Models\Transaction;
use App\Models\UserWallet;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut;

class UserWalletsDevices extends Donut
{
    protected $labels = ['未提现金额', '已提现金额', '待审核金额'];

    /**
     * 初始化卡片内容
     */
    protected function init()
    {
        parent::init();

        $color = Admin::color();
        $colors = [$color->primary(), $color->alpha('blue2', 0.5), $color->alpha('reg', 0.5)];

        $this->title('未封禁用户');
       // $this->subTitle('Last 30 days');
        $this->chartLabels($this->labels);
        // 设置图表颜色
        $this->chartColors($colors);
    }

    /**
     * 渲染模板
     *
     * @return string
     */
    public function render()
    {
        $this->fill();

        return parent::render();
    }

    /**
     * 写入数据.
     *
     * @return void
     */
    public function fill()
    {





        $uids = BlockedUser::pluck('user_id')->toArray();
        $reward_coins= (float) UserWallet::whereNotIn('user_id', $uids)->sum('reward_coins');//未提
        $reward_coins= (float)  sprintf("%.2f", $reward_coins / Setting::get('exchange_rate'));
        $trans_amount= (float) Transaction::whereNotIn('user_id', $uids)->where('status','approved')->sum('trans_amount');//已提现
        $locked_coins= (float) UserWallet::whereNotIn('user_id', $uids)->sum('locked_coins');//提现中
        $locked_coins=  (float) sprintf("%.2f", $locked_coins / Setting::get('exchange_rate'));
        $this->withContent($reward_coins, $trans_amount, $locked_coins);

        $this->withChart([$reward_coins, $trans_amount, $locked_coins]);
    }

    /**
     * 设置图表数据.
     *
     * @param array $data
     *
     * @return $this
     */
    public function withChart(array $data)
    {
        return $this->chart([
            'series' => $data
        ]);
    }

    /**
     * 设置卡片头部内容.
     *
     * @param mixed $desktop
     * @param mixed $mobile
     *
     * @return $this
     */
    protected function withContent($desktop, $mobile, $mobile1)
    {
        $blue = Admin::color()->alpha('blue2', 0.5);
        $blue1 = Admin::color()->alpha('reg', 0.5);
        $style = 'margin-bottom: 8px';
        $labelWidth = 120;

        return $this->content(
            <<<HTML
<div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
    <div style="width: {$labelWidth}px">
        <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
    </div>
    <div>{$desktop}</div>
</div>
<div class="d-flex pl-1 pr-1" style="{$style}">
    <div style="width: {$labelWidth}px">
        <i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
    </div>
    <div>{$mobile}</div>
</div>
<div class="d-flex pl-1 pr-1" style="{$style}">
    <div style="width: {$labelWidth}px">
        <i class="fa fa-circle" style="color: $blue1"></i> {$this->labels[2]}
    </div>
    <div>{$mobile1}</div>
</div>
HTML
        );
    }
}
